﻿using System;
using System.Diagnostics.Contracts;
using System.IO;
using OpenLS.Spreadsheet.Formats.Biff.Records;

namespace OpenLS.Spreadsheet.Formats.Biff.OfficeArt
{
    internal class OfficeArtMetafileHeader
    {
        private uint cbSize;
        private POINT ptSize;
        private RECT rcBounds;
        private uint cbSave;
        private byte compression;
        private byte filter;

        public void Read(BinaryReader reader)
        {
           
#if DEBUG
             ReadWriteChecker.CheckClass((t, r)=> t.Read(r), (t, w) => t.Write(w), reader, this);
            var pos = reader.BaseStream.Position;
#endif
            this.cbSize = reader.ReadUInt32();
            this.rcBounds = new RECT();
            rcBounds.Read(reader);
            this.ptSize = new POINT();
            ptSize.Read(reader);
            this.cbSave = reader.ReadUInt32();
            this.compression = reader.ReadByte();
            this.filter = reader.ReadByte();
            Contract.Assert((this.filter == 0xFE));
#if DEBUG
            Contract.Assert(reader.BaseStream.Position - pos == Size);
#endif
        }


        public int ByteLength
        {
            get { return Size; }
        }

        public static int Size
        {
            get { return 34; }
        }

        public void Write(BinaryWriter writer)
        {
#if DEBUG
            var pos = writer.BaseStream.Position;
#endif
            writer.Write(cbSize);
            rcBounds.Write(writer);
            ptSize.Write(writer);
            writer.Write(cbSave);
            writer.Write(compression);
            writer.Write(filter);
            Contract.Assert((this.filter == 0xFE));
#if DEBUG
            Contract.Assert(writer.BaseStream.Position - pos == Size);
#endif
        }
    }
}